大家好~可以叫我 vanillaSky 或 白臉貓,是資訊工程的學生,去年才剛踏入 Spring 的世界,做了一個 Spring Boot + Vue + PostgreSQL 的全端專案,還自己摸索了部署到Digital Ocean上。不過那次的經驗比較偏向「能跑就好」,沒有太多架構思維。後來我讀完了 《Java Spring Start Here》,現在正在研讀 《Spring Persistence with Spring Data and Hibernate》。本系列會透過實作來認識常見的 Spring annotations 與套件使用,邊寫邊學,並記錄我在學習過程中的踩坑經驗。
⚠️ :這是我第一次嘗試微服務,文章內容會偏向學習紀錄,有錯的話請大家指正,相互學習~
這 30 天,我會記錄以下主題:
透過爬蟲得到新聞文章,結合LLM,幫助我們快速接收新知、延伸發想濃縮成 Digest(摘要)的方式,最後透過 LINE Bot 把這些news digest每天推送給我們。
由 3 個主要微服務組成:
Spring 是目前 Java 常見的企業級框架,社群與資源非常豐富。
Spring Boot 在此基礎上,幫助我們更快起步,簡化配置,使開發者更注重商業邏輯的整合,特別適合來快速建立第一個服務。
不過,並不是所有情況都適合使用框架:
如果專案規模很小,純粹寫一個簡單工具或學習語言的語法基礎,框架反而會帶來額外負擔,因為框架會幫我們做很多事情(Many magic happened under the hood!!)。
至於我為什麼選用 Spring Boot?
我想學習現實企業常用的技術與架構。比起只會寫能「跑起來」的程式,我更希望透過這個系列,接觸到企業實務中會用到的概念(像六邊形架構、DDD、微服務),哪怕一開始會比較難。
寫 Spring Boot 有兩個觀念很重要:Convention over Configuration (CoC) 跟 Let the framework manage。前者讓我們少寫很多設定,後者則是因為 Spring Boot 幫忙管理依賴版本,所以很多套件在 pom.xml 裡根本不用手動填版本。
有許多前人的介紹文我就不再贅述,在這個系列裡,我會以 Spring Boot 為主,專注在快速實作與架構學習。
請在 pom.xml 配置檔確認:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.5.4</version>
<relativePath/>
</parent>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
看看有沒有配置成功摟~
@SpringBootApplication
public class MyApplication {
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
System.out.println("Hello Spring");
}
}
詳細內容可以參考我在 StackOverflow 上的回覆:
https://stackoverflow.com/questions/79731652/most-simple-spring-java-annotation-program-method-getbeanstring-in-the-type/79732272#79732272